class GraphicsController < ApplicationController
  # GET /graphics/new
  def new
    @graphic = Graphic.new
  end

  def create
    @graphic = Graphic.new(params[:graphic])
    @graphicable_object = params[:controller_type].singularize.capitalize.constantize.find(params[:graphicable_id])
    @graphic.graphicable = @graphicable_object

    respond_to do |format|
      if @graphic.save
        flash[:notice] = 'Graphic was successfully uploaded.'
        format.html { redirect_to :controller => params[:controller_type], :action => :show, :id => params[:graphicable_id] }
        format.xml  { head :created, :location => graphic_url(@graphic) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @graphic.errors.to_xml }
      end
    end
  end

  def destroy
    @graphic = Graphic.find(params[:id])
    @graphic.destroy

    respond_to do |format|
      flash[:notice] = 'Graphic was deleted.'
      format.html { redirect_to :controller => @graphic.graphicable_type.pluralize, :action => :show, :id => @graphic.graphicable_id }
      format.xml  { head :ok }
    end
  end
end
